1758B - XOR = Average - CodeForces Solution


constructive algorithms

Please click on ads to support us..

Python Code:

t = int(input())
for i in range(t):
    n = int(input()) 
    if(n%2==1):
        for i in range(n):
            print(n,end =" ")
        print() 
    else:
        print(1,3,end=" ") 
        for i in range(n-2):
            print(2,end = " ") 
        print()

C++ Code:

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>  //  --> PBDS
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds; 
using ll = long long;
using ull = unsigned long long;

const int mod = 1e9+7;
const int mod2 = 998244353;

#define what_is(x) cerr << #x << " is " << x << endl;
#define prec(n) fixed << setprecision(n)
#define inf (ll)1e18
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define all(x) (x).begin(),(x).end()
#define trail(x) __builtin_ctzll(x) // -> number of trailing zeros
#define pll pair<ll,ll>
#define mp make_pair
#define fr first
#define sc second
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define nl "\n"
#define lb lower_bound
#define ub upper_bound
#define oset tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> // (*s.find_by_order)(s.order_of_key)(insert,erase,size,lb,ub)
/*------------------------------------------------------------------------------------------------------------*/
ll countSetBits(ll n) { ll count = 0; while (n) { count += n & 1; n >>= 1;} return count; }
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
bool powerOfTwo(ll n) { return n && (!(n & (n-1))); }
void toLower(string& s) { transform(s.begin(), s.end(), s.begin(), ::tolower); }
void toUpper(string& s) { transform(s.begin(), s.end(), s.begin(), ::toupper); }
/*************************************************************************************************************/

vector<ll> primes; // all the primes till (1e7)
vector<bool> seive(1e7+10,true);
void createSeive()
{
    seive[0] = seive[1] = false;
    for(int i=2;i*i<=int(1e7);++i){
        if(seive[i])
        {
            for(int j=i*i;j<=int(1e7);j+=i) seive[j]=false;
        }
    }
    for(int i=0;i<seive.size();++i) if(seive[i]) primes.pb(i);
}

ll binexpo(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
        res = (res * a) % m;
        a = (a * a) % m;
        b >>= 1;
    }
    return res;
}
ll modInverse(ll n, ll mod)  // euler's totient --> eulers theorm --> fermat's
{
    return binexpo(n, mod - 2, mod);  // MMI of A is --> A^(mod-2) % mod
}
vector<ll>fact;
void factorial(ll n,ll mod)
{
    fact.resize(n+1);
    fact[0]=1;
    for(int i=1;i<=n;++i) fact[i] = (fact[i-1]*i) % mod;
}
ll nCrModPFermat(ll n, ll r, ll mod)  // nCr % mod calculation
{
    fact.resize(n+1);
    if (n < r) return 0;  // If n<r, then nCr should return 0
    if (r == 0) return 1;  // Base case
    fact[0] = 1;
    for (int i = 1; i <= n; i++) fact[i] = (fact[i - 1] * i) % mod;
    return (fact[n] * modInverse(fact[r], mod) % mod* modInverse(fact[n - r], mod) % mod)% mod;
}

bool isPrime(ll n)
{
    // Corner case
    if (n <= 1) return false;
    // Check from 2 to square root of n
    for (int i = 2; i*i <= n; i++)
        if (n % i == 0) return false;
    return true;
}

class DSU{
    vector<ll> parent;
    vector<ll> subtree_size;
    ll N;
public:
    DSU(ll n){
        N = n;
        parent = vector<ll>(n+1, 0);
        subtree_size = vector<ll>(n+1, 1);

        for(int i=1; i<=n; i++) parent[i] = i;
    }

    ll findRoot(ll u){
        while(u != parent[u]){
            parent[u] = parent[parent[u]]; //Path compression
            u = parent[u];
        }

        return u;
    }

    bool combine(ll u, ll v){
        ll ru = findRoot(u); // root of u
        ll rv = findRoot(v); // root of v

        if(ru == rv) return false; // no need to join(same group)
        
        // small to large merging --> (union by rank or size)
        if(subtree_size[ru] > subtree_size[rv]){
            parent[rv] = ru;
            subtree_size[ru] += subtree_size[rv];
        } else{
            parent[ru] = rv;
            subtree_size[rv] += subtree_size[ru];
        }
        return true;
    }
};
/********************* KMP (pattern matching)*********************/
ll kmp(string String, string pattern) {
  ll i = 0, j = 0, m = pattern.length(), n = String.length();
  pattern = '#' + pattern; //just shifting the pattern indices by 1
  vector < ll > piTable(m + 1, 0);
  for (int i = 2; i <= m; i++) {
    while (j <= m && pattern[j + 1] == pattern[i])
      piTable[i++] = ++j;
    j = 0;
  }
  j = 0;
  for (int i = 0; i < n; i++) {
    if (pattern[j + 1] != String[i]) {
      while (j != 0 && pattern[j + 1] != String[i])
        j = piTable[j];
    }
    j++;
    if (j == m) return (i - m + 1); // index of the pattern in the string
  }
  return -1; // not found
}
/******************************************************************/
void precompute()
{
    
}

void solve()
{
    
    int n; cin >> n;
    if(n&1)
    {
        for(int i=0;i<n;++i)
        {
            cout << 69 << " ";
        }
        cout << nl;
    }else{
        for (int i = 0; i < n-2; ++i)
        {
            cout << 4 << " ";
        }
        cout << "2 6";
        cout << nl;
    }
    
    
}

signed main() {
    
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // fast io
    precompute();
    int tc = 1;
    cin >> tc;
    for(int t=1;t<=tc;++t)
    {
        //cout << "Case #" << i << ": ";
        solve();
    } 
return 0;  
}
//end
 	        	 	 	 	   		 			    	


Comments

Submit
0 Comments
More Questions

1277A - Happy Birthday Polycarp
577A - Multiplication Table
817C - Really Big Numbers
1355A - Sequence with Digits
977B - Two-gram
993A - Two Squares
1659D - Reverse Sort Sum
1659A - Red Versus Blue
1659B - Bit Flipping
1480B - The Great Hero
1519B - The Cake Is a Lie
1659C - Line Empire
515A - Drazil and Date
1084B - Kvass and the Fair Nut
1101A - Minimum Integer
985D - Sand Fortress
1279A - New Year Garland
1279B - Verse For Santa
202A - LLPS
978A - Remove Duplicates
1304A - Two Rabbits
225A - Dice Tower
1660D - Maximum Product Strikes Back
1513A - Array and Peaks
1251B - Binary Palindromes
768B - Code For 1
363B - Fence
991B - Getting an A
246A - Buggy Sorting
884A - Book Reading